/*
* Copyright (c) 2011 Connection Road.  All rights reserved.
* This program and the accompanying material are made available
* under the terms of the Eclipse Public Licnese v1.0 which is
* available at http://www.eclipse.org/legal/epl-v10.html
*/

using System;
using System.Diagnostics;
using System.Windows.Forms;
using CrSyncFilesForms.Properties;
using CrSyncFilesForms.Utils;
using CrSyncFilesUtils;
using CrSyncFilesUtils.Enums;

namespace CrSyncFilesForms {
    public partial class CrSyncUiChangeAction : Form {

       public CrSyncUiChangeAction(FileSyncPairInfo pairInfo) {
           InitializeComponent();
           PairManager = ApplicationGlobals.PairManager;
           FolderPair = pairInfo;
       }

        public CrSyncUiChangeAction()
        {
            InitializeComponent();
        }


        private void CallDialogChangeActionLoad(object sender, EventArgs e) {

            // Color scheme
            BackColor = CRSyncColors.DialogBackGround;
            LabelTitle.ForeColor = CRSyncColors.Title;
            GroupShortExplanation.ForeColor = CRSyncColors.ForeColor;
            OptionContribute.ForeColor = CRSyncColors.ForeColor;
            OptionEcho.ForeColor = CRSyncColors.ForeColor;
            OptionSynchronize.ForeColor = CRSyncColors.ForeColor;
            LinkMoreInfo.LinkColor = CRSyncColors.LinkForeColor;


            Text = string.Format(Resources.TEXT_CHANGE_ACTION_FOR, FolderPair.FolderPairName);

            
            int actionTypeId = FolderPair.FolderPairActionTypeId;
            switch(actionTypeId){
                case (int)FolderPairActionTypeEnum.Synchronize :
                    OptionSynchronize.Checked = true;
                    break;
                case (int)FolderPairActionTypeEnum.Contribute:
                    OptionContribute.Checked = true;
                    break;
                case (int)FolderPairActionTypeEnum.Echo:
                    OptionEcho.Checked = true;
                    break;
                default :
                    OptionSynchronize.Checked = true;
                    break;
            }

            // NOTE : Remove from codeplex
            // Disable sync method selection when the current Folder Pair is a cloud storage pair.
            if ((FolderPair.LeftFolder.LocationType == CrSyncFileLocationTypes.Azure) || (FolderPair.RightFolder.LocationType == CrSyncFileLocationTypes.Azure))
            {
                OptionContribute.Enabled = false;
                OptionEcho.Enabled = false;
            }
            else
            {
                OptionContribute.Enabled = true;
                OptionEcho.Enabled = true;
            }

            AcceptButton = ButtonOK;
            CancelButton = ButtonCancel;
        }

        /// <summary>
        /// Required. Must be set during every call this window
        /// </summary>
        public FileSyncPairInfo FolderPair { get; set; }

        /// <summary>
        /// Required. Must be set during every call this window
        /// </summary>
        private FileSyncPairManager PairManager { get; set; }


        private void CallBackShowSynchronizeToolTip(object sender, EventArgs e) {
            var toolTip = new ToolTip();
            var explanation = Resources.SYNC_INFO_SYNCHRONIZE;
            toolTip.SetToolTip(OptionSynchronize, explanation);
        }

        private void CallBackShowEchoToolTip(object sender, EventArgs e) {
            var toolTip = new ToolTip();
            var explanation = Resources.SYNC_INFO_ECHO;
            toolTip.SetToolTip(OptionEcho, explanation);
        }

        private void CallBackShowContributeToolTip(object sender, EventArgs e) {
            var toolTip = new ToolTip();
            var explanation = Resources.SYNC_INFO_CONTRIBUTE;
            toolTip.SetToolTip(OptionContribute, explanation);
        }

        private void CallBackSelectSynchronize(object sender, EventArgs e) {
            var explanation = Resources.SYNC_INFO_SYNCHRONIZE;
            LabelShortExplanation.Text = explanation;
            FolderPair.FolderPairActionTypeId = (int)FolderPairActionTypeEnum.Synchronize;
            
        }

        private void CallBackSelectEcho(object sender, EventArgs e) {
            var explanation = Resources.SYNC_INFO_ECHO;
            LabelShortExplanation.Text = explanation;
            FolderPair.FolderPairActionTypeId = (int)FolderPairActionTypeEnum.Echo;
            
        }

        private void CallBackSelectContribute(object sender, EventArgs e) {
            var explanation = Resources.SYNC_INFO_CONTRIBUTE;
            LabelShortExplanation.Text = explanation;
            FolderPair.FolderPairActionTypeId = (int)FolderPairActionTypeEnum.Contribute;
           
        }

        private void CallBackOk(object sender, EventArgs e)
        {
            DialogResult = DialogResult.OK;
        }

        private void CallBackCancel(object sender, EventArgs e) {
            DialogResult = DialogResult.Cancel;
        }

        private void CallBackMoreInformation(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Process.Start(new ProcessStartInfo(Settings.Default.CFG_URL_ONLINE_DOC));
        }

        
        
    }
}
